<?php
!defined('BASE_PATH') && die('forbidden');



class core_helper_csv {
	
	public static function output($data, $name = 'output', $header = 1){
		
		header("Content-Type:application/vnd.ms-excel");
		header("Content-Disposition:filename=".$name.".csv");
		
		self::_output($data, $header);

	}

	public static function _output($data, $header = 1) {
		
		if($header){
			$keys = array_keys(current($data));
			array_unshift($data,$keys);
		}
		
		foreach($data as $k=>$v){
			foreach($v as $kk=>$vv){
				//is_numeric($vv) && $v[$kk] = "\t" . $vv;
				if(is_numeric($vv) && strlen($vv)<12){
					continue;
				}
				$v[$kk] = "\t" . $vv;//防止格式被转换
			}
			$data[$k] = implode(",", $v);
		}
		
		$data = implode(",\n", $data);
		
		echo $data.",\n";

	}

}


?>